Practice: A Multi-Agent Data Analysis Workflow with Ollama
Objective:
In this practical session, you will simulate a real-world data science workflow by creating and orchestrating two distinct, specialised AI agents.
Process:
You will build a “Data Strategist” to create an analysis plan, and then a “Python Coder” to write the code for that plan, acting as the project manager between them.
Environment:
This entire workflow will run locally on your machine using Ollama.
Estimated Time:
50-60 minutes.
Your first task is to create a high-level AI agent that plans a data analysis project.
gemma3:1b for our planning agent. It’s a capable and very lightweight model.ollama pull to download the model.ModelfileModelfile for the Strategist:Modelfile.strategist. Add the following content, which defines our agent’s persona.# Use gemma3:1b as the base model
FROM gemma3:1b
# Set a higher temperature for more creative planning
PARAMETER temperature 0.8
# Define the system prompt for the Data Strategist
SYSTEM """
You are a Senior Data Strategist. Your expertise is in
designing clear, concise, and actionable data analysis
plans. You are brilliant at strategy but you DO NOT
write code.
When given a description of a dataset, you must provide a
step-by-step analysis plan in Markdown format. The plan must
include the following sections:
1. **Project Goal:** A single sentence defining the
primary objective.
2. **Key Research Question:** One specific, answerable
question.
3. **Data Loading & Cleaning:** A short bulleted list of
initial steps.
4. **Exploratory Data Analysis (EDA):** A bulleted list of
at least three specific visualisations to create.
"""Create the Strategist Agent:
In your terminal, create the strategist model.
Use the command ollama create with the -f flag to specify the Modelfile.strategist.
Run the Agent:
Now, run the agent and give it the prompt for your project plan.
Use ollama run strategist to start the agent.
Prompt: I have a fictitious dataset named 'store_sales.csv' with the columns: 'date', 'product_category', 'units_sold', and 'revenue'.
Important: The agent will output a plan. Manually copy this entire plan, create a new file named project_plan.md, and paste the content into it. Save the file and then type /bye to exit the agent.
Now you’ll build the second agent. Its only job is to write Python code.
Choose a Coder Base Model:
We’ll use qwen2.5-coder:1.5b, a lightweight but capable model specialised for coding.
Again, use ollama pull to download the model.
Create the Modelfile for the Coder:
In the same directory, create Modelfile.coder and add the following:
# Use qwen2.5-coder:1.5b as the base model
FROM qwen2.5-coder:1.5b
# Use a low temperature for deterministic code
PARAMETER temperature 0.2
# Define the system prompt for the Python Coder
SYSTEM """
You are a junior Python developer. Your job is to write
clean, executable Python code based on a specific
instruction from a project plan.
- You MUST use the pandas, matplotlib, and seaborn
libraries.
- You write ONLY Python code. Do not include any
explanations or text outside of the code itself.
- Wrap the entire output in a single Markdown code
block (```python).
- Assume the data is already loaded into a pandas
DataFrame named 'df'.
"""Create the Coder Agent:
In your terminal, create the python_coder model from its Modelfile.
Use ollama create with the -f flag to specify the Modelfile.coder, just like you did for the strategist.
(Self-check: Run ollama list to confirm both strategist and python_coder are available.)
Now we have our two specialist agents ready for the integration step!
This is the integration step. You will act as the project manager, taking the plan from the strategist and giving a specific task to the python_coder.
Assign a Task to the Coder:
Open your project_plan.md file and look at the “Exploratory Data Analysis (EDA)” section. Choose one of the visualisation tasks (e.g., “Generate a bar chart of revenue by product category”) and copy the text.
Run the Coder Agent:
In your terminal, run your python_coder agent.
Manually paste the single EDA task you copied as a prompt for the python_coder and press Enter.
python_coder.analysis.py and paste the code into this file.analysis.py file.ollama ls to see the list of models, then use ollama rm <model_name> to remove them, e.g., ollama rm strategist and ollama rm python_coder.Multi-Agent Practice